import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import { defineConfig, loadEnv } from "vite";
// https://vitejs.dev/config/
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    server: {
      host: "0.0.0.0",
      port: 3001,
      proxy: {
        "/api": {
          target: env.VITE_HTTP_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [
          ElementPlusResolver({
            importStyle: "sass",
            directives: true,
            version: "1.2.0-beta.1",
          }),
        ],
      }),
      vue(),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: [`@use "@/assets/css/index.scss" as *;`],
        },
      },
    },
    resolve: {
      alias: [
        {
          find: "@",
          replacement: resolve(__dirname, "src"),
        },
        { find: /^~/, replacement: "" },
      ],
    },
    optimizeDeps: {
      exclude: ["vuex"],
    },
  });
};
